package com.ttdc.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.ttdc.pojo.Tabl;
import com.ttdc.pojo.TablExample;
import com.ttdc.service.TablService;


@Controller
public class qtablController {
	@Autowired
	private TablService tablService;
	private TablExample example;

		
		// 查询所有数据
		@RequestMapping("/qtb_list")
		public String selectByAll(Model model) {
			List<Tabl> list = tablService.selectByAll();
			model.addAttribute("list", list);
			return "qtable";
		}
	
	
		// 用条件查询所有的订单信息
		@RequestMapping("/qtb_selectAll")
		public String selectAll(Model model) {
			example = new TablExample();
			TablExample.Criteria criteria = example.createCriteria();
			criteria.andTbIdIsNotNull();
			List<Tabl> list = tablService.selectByExample(example);
			model.addAttribute("list", list);
			return "qtable";
		}

	

	// 查询 可多條件查詢
	@RequestMapping("qtb_selectById")
	public String selectByPrimaryKey(Tabl tabl, HttpSession session, Model model) {
		example = new TablExample();
		TablExample.Criteria c = example.createCriteria();
		if (tabl == null) {
			return "qtable";
		} else {
			if (tabl.getTbUse() != null) {
				// 根據餐桌使用状态查詢
				System.out.println(tabl.getTbUse());

				c.andTbUseEqualTo(tabl.getTbUse());
				List<Tabl> list = tablService.selectByExample(example);
				model.addAttribute("list", list);
				session.setAttribute("list",list);
			}
			if (tabl.getTbId() != null) {
				// 根據餐桌號查詢訂單
				System.out.println(tabl.getTbId());
				c.andTbIdEqualTo(tabl.getTbId());
				List<Tabl> lst = tablService.selectByExample(example);
				model.addAttribute("list", lst);
			}
	
		
			return "qtable";
		}
	}

}
